package com.wteam.modules.system.util;

import org.apache.commons.collections.list.UnmodifiableList;
import org.apache.poi.ss.formula.functions.T;

import java.lang.reflect.Field;
import java.util.List;

public class CollectionUtil {
    public static List getModifiableList(List list) throws IllegalAccessException {
        Field pro = getDeclaredField(list, "list");
        pro.setAccessible(true);
        List<T> result = (List<T>) pro.get(list);
        return result;
    }

    public static Field getDeclaredField(Object object, String fieldName){
        Field field = null ;
        Class<?> clazz = object.getClass() ;
        for(; clazz != Object.class ; clazz = clazz.getSuperclass()) {
            try {
                field = clazz.getDeclaredField(fieldName) ;
                return field ;
            } catch (Exception e) {
                //这里甚么都不要做！并且这里的异常必须这样写，不能抛出去。
                //如果这里的异常打印或者往外抛，则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
            }
        }
        return null;
    }
}
